var config = require ('../../config.js');
var configUtils = require ('./configUtils.js');
var LOG_SEREVR = 'http://47.120.74.135';

module.exports = {
  post (data) {
    var logServer = configUtils.getConfig ('log', 'server', LOG_SEREVR);
    var url = logServer + '/api/log/add';
    return http.postJson (url, data);
  },
  log (msg, type) {
    type = type || 1;
    return this.post ({
      battery: device.getBattery (),
      type: type,
      msg: msg,
      phoneNumber: config.phoneNumber,
      timeStamp: Date.now (),
    });
  },
  info () {
    var log = console.log;
    log.apply (console, arguments);
    return;
    var http$ = configUtils.getConfig ('log', 'http', false);
    var join = Array.prototype.join;
    var data = {
      type: '2',
      curApp: '未知',
      msg: join.call (arguments, ' '),
      battery: Number (device.getBattery ()),
      phoneNumber: config.phoneNumber,
      createTime: new Date (),
    };
    if (http$) {
      try {
        var res = this.post (data);
        // console.log(data);
        // console.log(res.body.string());
      } catch (e) {
        console.log ('http log error:', e);
      }
    } else {
      var log = console.log;
      log.apply (console, arguments);
    }
  },
  print () {
    var log = console.log;
    log.apply (console, arguments);
  },
};
